package com.varian.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.varian.service.annotation.Resubmit;
import com.varian.service.web.BaseController;
import com.varian.system.dto.ApiErrorLogHandleDTO;
import com.varian.system.dto.ApiLogPageDTO;
import com.varian.system.service.IApiLogService;
import com.varian.system.vo.ApiLogItemVO;
import com.varian.system.vo.ApiLogVO;
import com.varian.tool.result.IR;
import com.varian.tool.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ben
 * @since 2024/7/23
 */
@Resubmit
@RestController
@Tag(name = "API日志控制层")
@RequestMapping("/api-log")
public class ApiLogController extends BaseController<IApiLogService> {

    @GetMapping("page")
    @Operation(summary = "API日志列表")
    @PreAuthorize("hasAuthority('api-log:page')")
    public R<Page<ApiLogItemVO>> page(@Validated ApiLogPageDTO dto) {
        return R.data(baseService.page(dto));
    }

    @GetMapping("{id:\\d+}")
    @Operation(summary = "API日志详情")
    @PreAuthorize("hasAuthority('api-log:detail')")
    public R<ApiLogVO> detail(@PathVariable("id") Long id) {
        return R.data(baseService.detail(id));
    }

    @PutMapping("error-handle/{id:\\d+}")
    @Operation(summary = "API日志错误处理")
    @PreAuthorize("hasAuthority('api-log:error-handle')")
    public IR errorHandle(@PathVariable("id") Long id, @Validated @RequestBody ApiErrorLogHandleDTO dto) {
        return R.status(baseService.errorHandle(id, dto));
    }
}
